package com.mindskip.xzs.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.domain.Phase;
import com.mindskip.xzs.repository.PhaseMapper;
import com.mindskip.xzs.service.PhaseService;
import com.mindskip.xzs.utility.TreeUtil;
import com.mindskip.xzs.viewmodel.admin.education.PhasePageResponseVM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PhaseServiceImpl extends BaseServiceImpl<Phase> implements PhaseService {

    private final PhaseMapper phaseMapper;

    @Autowired
    public PhaseServiceImpl(PhaseMapper phaseMapper) {
        super(phaseMapper);
        this.phaseMapper = phaseMapper;
    }

    @Override
    public Phase selectById(Integer id) {
        return super.selectById(id);
    }

    @Override
    public int updateByIdFilter(Phase record) {
        return super.updateByIdFilter(record);
    }


    @Override
    public List<Phase> allPhase() {
        return phaseMapper.allPhase();
    }

    @Override
    public List<Phase> newAllPhase() {
        return TreeUtil.getTree(phaseMapper.newAllPhase());
    }

    @Override
    public List<Phase> parentPhase() {
        return TreeUtil.getTree(phaseMapper.parentPhase());
    }

    @Override
    public PageInfo<Phase> page(PhasePageResponseVM requestVM) {
        return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id asc ").doSelectPageInfo(() ->
                phaseMapper.page(requestVM)
        );
    }



}
